# @Time : 2024-11-12 9:38
# @Author : Fioman 
# @Phone : 13149920693
"""
模拟测试Eap,在界面上点击Mock Request的时候,调用的一些方法
"""

from eap_control import eap_request, resp_parse
from eap_control.eap_config import EapConfig
from eap_control.eap_logger import EapLogger

eapLog = EapLogger()
ec = EapConfig()


class MockRequest:
    """
    模拟请求,界面上点击对应的请求的时候,调用这个方法,每次请求的时候,去更新Send里面的值,以及Response
    里面的值
    """

    @staticmethod
    def mock_request_from_web(requestMethod):
        """
        界面上点击mockRequest按钮之后调用的逻辑
        :param requestMethod: 要请求测试的request方法.
        :return:
        """
        from app.device_state import DeviceState
        ds = DeviceState()
        if requestMethod == "AreYouThereRequest":
            response = eap_request.request_are_you_there()
            resp_parse.parse_are_you_there_response(requestMethod, response)
        elif requestMethod == "InitialDataRequest":
            # 模拟报警
            response = eap_request.request_initial_data()
            resp_parse.parse_initial_data_response(requestMethod, response)
        elif requestMethod == "EquipmentCurrentDateTime":
            response = eap_request.request_equipment_current_date_time()
            resp_parse.parse_equipment_current_date_time_response(requestMethod, response)
        elif requestMethod == "EquipmentInformation":
            response = eap_request.request_equipment_information("1", ds.orderUsedId, "1")
            resp_parse.parse_equipment_information_response(requestMethod, response)
        elif requestMethod == "EquipmentTotalCount":
            response = eap_request.request_equipment_total_count("2")
            resp_parse.parse_equipment_total_count_response(requestMethod, response)
        elif requestMethod == "EquipmentStatus":
            response = eap_request.request_equipment_status(equipment_status="1")
            resp_parse.parse_equipment_status_response(requestMethod, response)
        elif requestMethod == "EquipmentInformation":
            response = eap_request.request_equipment_information("1", ds.orderUsedId,"1")
            resp_parse.parse_equipment_information_response(requestMethod, response)
        elif requestMethod == "AlarmWarningDataReport":
            response = eap_request.request_alarm_warning_data_report(alarm_type="S", report_type="R", aw_code="1", aw_text="PLC通信异常")
            resp_parse.parse_alarm_warning_data_report_response(requestMethod, response)
        elif requestMethod == "ProcessDataReport":
            proc_data_list = {
                "proc_data": [
                    {
                        "data_value": "1.3",
                        "data_item": " Border Thickness"
                    },
                    {
                        "data_value": " 1.5 ",
                        "data_item": " Copper Thickness    "
                    },
                    {
                        "data_value": " 5.6 ",
                        "data_item": " Copper Area   "
                    },
                    {
                        "data_value": " 600 ",
                        "data_item": " Cutter Move Speed   "
                    },
                    {
                        "data_value": " 800 ",
                        "data_item": " Cutter Down Speed    "
                    },
                    {
                        "data_value": " 650 ",
                        "data_item": " Cutter Load Speed    "
                    }
                ]
            }
            response = eap_request.request_process_data_report(report_type="0", judge="1",
                                                               process_name="lot135", pn_name="recipeTest",
                                                               panel_id="1", proc_data_list=proc_data_list)
            resp_parse.parse_process_data_report_response(requestMethod, response)
        elif requestMethod == "UserLoginLogoutReport":
            response = eap_request.request_user_login_logout_report(work_type="1", user_no="员工01")
            resp_parse.parse_user_login_logout_report_response(requestMethod, response)
        elif requestMethod == "FilePathAndParameterRequest":
            response = eap_request.request_file_path_and_parameter_request(eqp_id=ec.user_id,lot_id=ds.lotIdUsed,
            pn_id=ds.orderUsedId,panel_id=ds.workIndex)
            resp_parse.parse_file_path_and_parameter_request_response(requestMethod, response)
        elif requestMethod == "CIMMessageCommand":
            response = eap_request.deal_cim_message_command(data={"body": {"action_type": "0", "interval_second_time": 10, "cim_message": "测试消息"}})
        else:
            eapLog.print_and_debug(f"未处理的请求: {requestMethod}")
